home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 526 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: news.clark.net!not-for-mail
  2. From: eamick@clark.net (Eric Amick)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Problem with stringcopy
  5. Date: 6 Jan 1996 17:11:22 GMT
  6. Organization: the end of my rope
  7. Message-ID: <4cmafq$bm5@clarknet.clark.net>
  8. References: <4clguu$9fs@eagle.novo.dk> <yewvimppjz5.fsf@hyll.idt.unit.no>
  9. NNTP-Posting-Host: explorer.clark.net
  10. Mime-Version: 1.0
  11. Content-Type: TEXT/PLAIN; charset=ISO-8859-1
  12. Content-Transfer-Encoding: 8bit
  13. X-Newsreader: TIN [UNIX 1.3 950726BETA PL0]
  14.  
  15. Amund Tveit (amundt@pvv.unit.no) wrote:
  16. >[Morten Brun]
  17. >
  18. >|   How do i do a partial stringcopy i.e. copy from a specific position in
  19. >|   a string and a certain numbers of bytes. I am looking for a function
  20. >|   like target = Stringcopy(source, startpos, length)
  21. >
  22. >You can try something like this :
  23. >char *Stringcopy(char *source, int startpos, size_t length)
  24. >{
  25. >    char tmpstring[SIZEBIGENOUGH];
  26. >    strncpy((char *)(source+startpos),tmpstring,length);
  27. >    return tmpstring;
  28. >}
  29.  
  30. This won't work as written; the first two arguments to strncpy() are 
  31. reversed.  The cast is also unnecessary.
  32.  
  33. -- 
  34. Eric Amick            eamick@clark.net
  35. Columbia, MD            Public key available via finger
  36.